<html>
<head><meta charset="utf-8"><title>compare dyn ptr for equality · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html">compare dyn ptr for equality</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="193662240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193662240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193662240">(Apr 11 2020 at 14:08)</a>:</h4>
<p>I have 2 <code>Const { ty: &amp;dyn A, val: Value(ByRef { alloc: Allocation { bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [(Size { raw: 0 }, ((), alloc2)), (Size { raw: 8 }, ((), alloc4))] })</code> and want to check if they are equal. for arrays I can use <code>destructure_const</code> but that is wrong here afaict.</p>



<a name="193662562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193662562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193662562">(Apr 11 2020 at 14:16)</a>:</h4>
<p>*two <code>&amp;dyn A</code> with a value of the above</p>



<a name="193663438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663438">(Apr 11 2020 at 14:39)</a>:</h4>
<p><span class="user-mention" data-user-id="263033">@Banga Bangassou</span> <code>dyn Trait</code> shouldn't be considered to have "structural match"</p>



<a name="193663442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663442">(Apr 11 2020 at 14:39)</a>:</h4>
<p>we can't allow it</p>



<a name="193663491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663491">(Apr 11 2020 at 14:40)</a>:</h4>
<p>if it ICEs right now, that's perfect, unless you want to change the structural match conditions</p>



<a name="193663511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663511">(Apr 11 2020 at 14:40)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="116083">@pnkfelix</span> <code>dyn Trait</code> is actually unimplementable unlike raw/fn pointers</p>



<a name="193663612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663612">(Apr 11 2020 at 14:43)</a>:</h4>
<p>oh <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> completely forgot about that.</p>
<blockquote>
<p>if it ICEs right now, that's perfect, unless you want to change the structural match conditions</p>
</blockquote>
<p>wouldn't it be better if we emit an error instead of an ICE though</p>



<a name="193663654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663654">(Apr 11 2020 at 14:44)</a>:</h4>
<p>no, unless that error is the right one</p>



<a name="193663659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663659">(Apr 11 2020 at 14:44)</a>:</h4>
<p>hence "unless you want to change the structural match conditions"</p>



<a name="193663748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663748">(Apr 11 2020 at 14:46)</a>:</h4>
<p>I mean something like "<code>&amp;dyn A</code>  cannot be used a const parameter"</p>



<a name="193663830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663830">(Apr 11 2020 at 14:48)</a>:</h4>
<p>unless it's done in the right place, it's better to ICE IMO</p>



<a name="193663838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663838">(Apr 11 2020 at 14:49)</a>:</h4>
<p>but this is specifically because it's an unstable feature</p>



<a name="193663844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663844">(Apr 11 2020 at 14:49)</a>:</h4>
<p>where we <em>want</em> the compiler to crash if something isn't implemented yet</p>



<a name="193663900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663900">(Apr 11 2020 at 14:50)</a>:</h4>
<p>oh dear can we pattern-match on closures?!</p>



<a name="193663921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193663921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193663921">(Apr 11 2020 at 14:51)</a>:</h4>
<p>oh but you can't create them without loops, heh</p>



<a name="193664099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193664099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193664099">(Apr 11 2020 at 14:55)</a>:</h4>
<p>wait you can't have them in the type of constants at all</p>



<a name="193664142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193664142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193664142">(Apr 11 2020 at 14:56)</a>:</h4>
<p>okay so we're fine pattern-matching-wise</p>



<a name="193678820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678820">(Apr 11 2020 at 20:48)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span>  you can with <code>const X: impl Fn() = || {};</code></p>



<a name="193678825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678825">(Apr 11 2020 at 20:49)</a>:</h4>
<p>(which is unstable)</p>



<a name="193678828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678828">(Apr 11 2020 at 20:49)</a>:</h4>
<p>yeah but <code>ty::Closure</code> isn't in the typeck type</p>



<a name="193678834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678834">(Apr 11 2020 at 20:49)</a>:</h4>
<p>ah, you mean like that</p>



<a name="193678838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678838">(Apr 11 2020 at 20:49)</a>:</h4>
<p>match checking should see <code>ty::Opaque</code> there</p>



<a name="193678840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678840">(Apr 11 2020 at 20:49)</a>:</h4>
<p>yep, true</p>



<a name="193678843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678843">(Apr 11 2020 at 20:49)</a>:</h4>
<p>which.... ugh</p>



<a name="193678848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678848">(Apr 11 2020 at 20:49)</a>:</h4>
<p>is not allowed...?</p>



<a name="193678850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678850">(Apr 11 2020 at 20:49)</a>:</h4>
<p>(I hope)</p>



<a name="193678851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678851">(Apr 11 2020 at 20:49)</a>:</h4>
<p>I'm not sure we account for <code>ty::Opaque</code>s in match checking</p>



<a name="193678854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678854">(Apr 11 2020 at 20:49)</a>:</h4>
<p><span class="user-mention" data-user-id="126931">@centril</span> the code barely has a blacklist or two</p>



<a name="193678899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678899">(Apr 11 2020 at 20:50)</a>:</h4>
<p>it's not very defensively written :(</p>



<a name="193678923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/compare%20dyn%20ptr%20for%20equality/near/193678923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/compare.20dyn.20ptr.20for.20equality.html#193678923">(Apr 11 2020 at 20:50)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> yea; <span aria-label="cry" class="emoji emoji-1f622" role="img" title="cry">:cry:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>